class TDataKV:
    def __init__(self):
        self.dataDict ={}
    def set(self, key , value):
        self.dataDict[key] = value
    def get(self , key):
        res = None if not key in self.dataDict.keys() else self.dataDict[key]
        return  res

    def getDefaultValue(self , key , default=""):
        res = default
        if key in self.dataDict.keys():
            res = self.dataDict[key]
        return  res
    def getStr(self, key):
        return  self.getDefaultValue(key,'')
    def getNumber(self, key):
        return  self.getDefaultValue(key , 0)


    def webAction(self , result , params , request):
        try:
            ac = ""
            key = ""
            value = None
            for k , v in params.items():
                if "ac" ==k:
                    ac = v
                elif "key" ==k:
                    key = v
                elif "v" == k :
                    value = v
            if ac=="set" :
                if key=="":
                    result["error"]['code'] = -10
                    result["error"]['message'] = "key is error."
                else:
                    self.set(key , value)
                    result["result"]={
                        "status": 1,
                        "ac": ac,
                        "key": key
                    }
            elif ac=="get":
                if key=="":
                    result["error"]['code'] = -10
                    result["error"]['message'] = "key is error."
                else:
                    result["result"]={
                        "status": 1,
                        "ac": ac,
                        "key": key,
                        "value": self.get(key)
                    }
            else:
                result["error"]['code'] = -1
                result["error"]['message'] = "ac is error."
        except Exception as er:
            print(er)

dataKv = TDataKV()